package com.q.springboot.framework.config.redisson;

import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;
import java.util.concurrent.TimeUnit;

@Slf4j
public abstract class RMessageProducer<T extends Serializable> extends AbstractQueue {

    /**
     * 发送延时消息
     *
     * @param message
     * @param delay
     * @param timeUnit
     */
    public void sendMessage(T message, long delay, TimeUnit timeUnit) {
        log.info("rMessage sendMessage: {}, delayTime {}, TimeUnit {}", message.toString(), delay, timeUnit.name());
        super.getRDelayedQueue().offer(message, delay, timeUnit);
        super.getTopic().publish(this.hashCode());
    }

    /**
     * 发送异步消息
     *
     * @param message
     */
    public void sendMessage(T message) {
        this.sendMessage(message, 0, TimeUnit.MILLISECONDS);
    }

}
